import React, { Component } from 'react'
import { Select } from 'antd'
import { getAllChannels } from 'api/channel'

export default class SelectChannel extends Component {
  state = {
    channels: [],
  }

  getChannels = async () => {
    const res = await getAllChannels()
    this.setState({ channels: res.data.channels })
  }

  componentDidMount() {
    this.getChannels()
  }

  render() {
    const { channels } = this.state
    const { value, onChange } = this.props

    return (
      <Select value={value} onChange={onChange} placeholder="请选择频道">
        {channels.map((item) => (
          <Select.Option key={item.id} value={item.id}>
            {item.name}
          </Select.Option>
        ))}
      </Select>
    )
  }
}
